﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Windows.Shapes;
using System.Windows.Media;
using System.Windows.Media.Animation;

namespace Animation
{
    public partial class MoveBallPage : PhoneApplicationPage
    {
        public MoveBallPage()
        {
            InitializeComponent();
        }

        private void barPlay_Click(object sender, EventArgs e)
        {
            myStoryboard.Begin();
			myStoryboard2.Begin();
        }

        private void barPasuse_Click(object sender, EventArgs e)
        {
            myStoryboard.Pause();
			myStoryboard2.Pause();
        }
        Storyboard myStoryboard;
        private void myCanvas_Loaded(object sender, RoutedEventArgs e)
        {
            //Create new ball
            Ellipse ball1 = new Ellipse();
            ball1.Width = 100.0;
            ball1.Height = 100.0;
            ball1.Fill = new SolidColorBrush(Colors.Blue);
            ball1.SetValue(Canvas.TopProperty, 50.0);
            ball1.SetValue(Canvas.LeftProperty, 50.0);

            //Storyboard Double, Color, Point
            myStoryboard = new Storyboard();
            DoubleAnimation doubleAnimate = new DoubleAnimation();
            //1 second for animate
            doubleAnimate.Duration = new Duration(TimeSpan.FromSeconds(1.0));
            doubleAnimate.From = 50.0;
            doubleAnimate.To = 200.0;
            doubleAnimate.AutoReverse = true;
            doubleAnimate.RepeatBehavior = new RepeatBehavior(10.0);
            Storyboard.SetTarget(doubleAnimate, ball1);
            Storyboard.SetTargetProperty(doubleAnimate, new PropertyPath("(Canvas.Left)"));
            myStoryboard.Children.Add(doubleAnimate);

            ColorAnimation colorAnimate = new ColorAnimation();
            colorAnimate.Duration = new Duration(TimeSpan.FromSeconds(1.0));
            colorAnimate.From = Colors.Blue;
            colorAnimate.To = Colors.Green;
            colorAnimate.RepeatBehavior = new RepeatBehavior(10.0);
            colorAnimate.AutoReverse = true;
            Storyboard.SetTarget(colorAnimate, ball1);
            Storyboard.SetTargetProperty(colorAnimate, new PropertyPath("(Ellipse.Fill).(SolidColorBrush.Color)"));
            myStoryboard.Children.Add(colorAnimate);

            myCanvas.Children.Add(ball1);
        }
    }
}